package com.xuelang.pipeline.artifact.entry.resource;

import com.xuelang.pipeline.artifact.app.resource.ArtifactNamespaceService;
import com.xuelang.pipeline.artifact.client.common.request.PageParam;
import com.xuelang.pipeline.artifact.client.common.result.ApiResult;
import com.xuelang.pipeline.artifact.client.common.result.PageRecord;
import com.xuelang.pipeline.artifact.client.resource.IArtifactNamespaceService;
import com.xuelang.pipeline.artifact.client.resource.dto.ArtifactNamespaceDTO;
import com.xuelang.pipeline.artifact.client.resource.dto.ArtifactNamespaceQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 镜像仓库命名空间服务web控制类
 *
 * @author xiwen.zxg
 * @since 2024/5/28
 */
@Slf4j
@RestController
@RequestMapping("/artifact-namespace")
public class ArtifactNamespaceController implements IArtifactNamespaceService {

    @Autowired
    private ArtifactNamespaceService artifactNamespaceService;

    @Override
    public ApiResult<PageRecord<ArtifactNamespaceDTO>> pageArtifactNamespaceList(PageParam<ArtifactNamespaceQuery> dtoPageParam) {
        return ApiResult.success(artifactNamespaceService.pageList(dtoPageParam));
    }

    @Override
    public ApiResult<List<ArtifactNamespaceDTO>> conditionalArtifactNamespaceList(ArtifactNamespaceQuery artifactNamespaceQuery) {
        return ApiResult.success(artifactNamespaceService.list(artifactNamespaceQuery));
    }

    @Override
    public ApiResult<Boolean> addArtifactNamespace(ArtifactNamespaceDTO artifactNamespaceDTO) {
        return ApiResult.success(artifactNamespaceService.add(artifactNamespaceDTO));
    }

    @Override
    public ApiResult<Boolean> updateArtifactNamespace(ArtifactNamespaceDTO artifactNamespaceDTO) {
        return ApiResult.success(artifactNamespaceService.update(artifactNamespaceDTO));
    }

    @Override
    public ApiResult<Boolean> deleteArtifactNamespace(String uuid) {
        return ApiResult.success(artifactNamespaceService.delete(uuid));
    }

    @Override
    public ApiResult<ArtifactNamespaceDTO> queryArtifactNamespace(String uuid) {
        return ApiResult.success(artifactNamespaceService.query(uuid));
    }
}
